package com.tank.client;

import com.tank.protobuf.DataInfo;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * Created with IntelliJ IDEA.
 * User: SuQiEr
 * Date:2017/5/30 0030
 * Time: 上午 9:54
 * To change this template use File | Settings | File Templates.
 */
public class ChatClientHandler extends SimpleChannelInboundHandler<DataInfo.ParentMessag> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, DataInfo.ParentMessag msg) throws Exception {
        System.out.println(String.format("消息 %s",msg));
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        DataInfo.Student student = DataInfo.Student.newBuilder().setName("tank").setAge(25).setAddress("魔都").build();
        DataInfo.ParentMessag parentMessag = DataInfo.ParentMessag.newBuilder().setDataType(DataInfo.ParentMessag.DateType.StudentType).setStudent(student).build();
        System.out.println("name:{}"+parentMessag.getStudent().getName());
        ctx.writeAndFlush(parentMessag);
    }
}
